package cn.edu.neusoft.food229.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import java.util.List;
import cn.edu.neusoft.food229.R;
import cn.edu.neusoft.food229.bean.Comments;

public class CommentsAdapter extends RecyclerView.Adapter {
    private List<Comments> list;
    private Context context;
    private LayoutInflater layoutInflater;
    public CommentsAdapter(Context context,List<Comments>list){
       this.context=context;
        this.list=list;
        layoutInflater=LayoutInflater.from(context);
    }
    public void  setList(List<Comments> list){
        this.list=list;
        notifyDataSetChanged();
    }
    public class ViewHolder extends  RecyclerView.ViewHolder {
        TextView tv_name,tv_date,tv_intro,tv_shopname,tv_address;
//        ImageView imageView;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
//            imageView=itemView.findViewById(R.id.imageView12);
            tv_name=itemView.findViewById(R.id.textView32);
            tv_date=itemView.findViewById(R.id.textView28);
            tv_intro=itemView.findViewById(R.id.textView30);
           tv_shopname=itemView.findViewById(R.id.textView34);
            tv_address=itemView.findViewById(R.id.textView36);
        }
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v=layoutInflater.from(layoutInflater.getContext()).inflate(R.layout.comments,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        final Comments bean=(Comments) list.get(position);
        if(bean==null)return;
      ViewHolder viewHolder=(ViewHolder) holder;
        viewHolder.tv_name.setText(bean.getFoodname());
        viewHolder.tv_date.setText(bean.getOrder_time());
        viewHolder.tv_intro.setText(bean.getContent());
     viewHolder.tv_shopname.setText(bean.getShopname());
        viewHolder.tv_address.setText(bean.getAddress());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, bean.getContent()+bean.getContent()+"  ", Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public int getItemCount() {
        if(list!=null){
            return list.size();}//若使用对象是，避免出现空指针
        else
            return 0;//空条目是返回0
    }
}
